﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Planer.Model;
using Planer.Model.Validators.Base;
using Planer.Model.Validators;

namespace Planer.UI.Forms
{
    public partial class RegisterUserForm : Form
    {
        public RegisterUserForm()
        {
            InitializeComponent();
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {
            PasswordValidator pv = new PasswordValidator();
            pv.Validate(textBoxPassword.Text, textBoxConfirmPassword.Text);

            user usr = new user() { name = textBoxName.Text, email = textBoxMail.Text, password_hash = textBoxPassword.Text };
            ModelResult mr = UserModel.GetInstance().SaveOrUpdateUser(usr);
            if (mr.Status == OperationStatusType.ERROR || pv.Status == OperationStatusType.ERROR)
            {
                MessageBoxUtils.ShowErrorBox(mr.ShowAllMessages + pv.FirstError);
                return;
            }
            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
        }
    }
}
